package com.yixun.qfbao.hander;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.OrganizationService;
import com.yixun.qfbao.api.service.ThirdPartyApiService;
import com.yixun.qfbao.apidto.IsM2MerchantReqDto;
import com.yixun.qfbao.apidto.IsM2MerchantResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.IsM2MerchantReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * 判断是否是和M2合作的商户
 * @author lxj
 *
 */
@Service("isM2MerchantHander")
public class IsM2MerchantHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(IsM2MerchantHander.class);
	
	@Autowired
	private ThirdPartyApiService thirdPartyApiService;
	
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		IsM2MerchantReqVo req = (IsM2MerchantReqVo)reqDto;
		IsM2MerchantReqDto reqDto1 = req.getParams();
		BaseResponseDTO<IsM2MerchantResDto> res = new BaseResponseDTO<IsM2MerchantResDto>();
		IsM2MerchantResDto resDto = new IsM2MerchantResDto();
		try {
			resDto = thirdPartyApiService.isM2Merchant(reqDto1);
		}catch(TServerException e){
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg(e.getErrorMsg());
		} catch (Exception e) {
			logger.error("IsM2MerchantHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("系统异常");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
